<nav class="navbar navbar-default">
    <div class="container-fluid nav-style">
        <div class="navbar-header">
            <a class="navbar-brand" href="#">
                <img src="/images/timg.jpg" alt="知乎导航图片">
            </a>
        </div>
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav">
                <li><a href="/main">首页</a></li>
            </ul>
            <!--通过关键字进行搜索-->
            <form class="navbar-form navbar-left" action="/main/username" method="post">
                <div class="form-group">
                    <input type="text" name="keyword" pattern="[\u4e00-\u9fa5]{1,4}" class="form-control searchContent" placeholder="输入作者姓名搜索..." style="width: 300px">
                </div>
                <button type="submit" class="btn btn-default search">搜索</button>
            </form>
            <ul class="nav navbar-nav">
                <!--模态框发表文章-->
                <li>
                    <% include post %>
                </li>
                <li>
                    <% include upload %>
                </li>
                <li><a href="/shunjianjiyi">瞬间记忆</a></li>
                <!--头像显示区域-->
                <!--在找不到src路径时会执行onerror的代码onerror="this.src='url' "-->
                <li><img src="/userFile/<%= user.name %>.jpg" onerror="this.src='/userFile/user.jpg'" alt="用户头像" class="userPhoto"></li>
                <li class="dropdown userNav">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"><%= user.name %><span class="caret"></span></a>
                    <ul class="dropdown-menu">
                        <li><a href="/u/<%= user.name %>">个人中心</a></li>
                        <li><a href="/logout">退出</a></li>
                    </ul>
                </li>
            </ul>
        </div>
    </div>
</nav>
<script>
    $(function () {
        $('.search').click(function (e) {
            if($('input[name=keyword]').val().length==0){
               //当不输入关键字内容时，会阻止默认提交事件
               e.preventDefault();
            }
        })
    })
</script>